package com.finace.money.presenter;

import com.finace.money.data.bean.BannerBean;
import com.finace.money.data.bean.StatusListBean;
import com.finace.money.net.rto_rxbuild.RxHttpReponseCompat;
import com.finace.money.net.rto_subscriber.ProgressDialogSubcriber;
import com.finace.money.net.rto_subscriber.ProgressSubcriber;
import com.finace.money.presenter.contract.MainHomeContract;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhangpeng on 2018/1/16.
 */

public class MainHomePresenter extends BasePresenter<MainHomeContract.IMainHomeModel,MainHomeContract.View>{


    public MainHomePresenter() {

    }

    @Inject
    public MainHomePresenter(MainHomeContract.IMainHomeModel iMainHomeModel, MainHomeContract.View view) {
        super(iMainHomeModel, view);
    }

    public List<StatusListBean> getList(List<StatusListBean> statusLists) {

        List<StatusListBean> imList = new ArrayList<>();
        if(null != statusLists && statusLists.size()>0){
            for (StatusListBean bean:statusLists) {
                if(bean.getM_Body().getM_IsMain() == 1){
                    imList.add(bean);
                }
            }
        }
        return imList;
    }

    public void getBanner(){

        mModel.getBanner().compose(RxHttpReponseCompat.<BannerBean>compatResult())
                .subscribe(new ProgressSubcriber<BannerBean>(mContext,mView) {
                    @Override
                    public void onNext(BannerBean bannerBean) {

                        if (hasView()) {
                            mView.showBanner(bannerBean);
                        }

                    }
                });
    }
}
